/*
 ============================================================================
 Name		: FbListItem.cpp
 Author	  : ceze
 Version	 :
 Copyright   : FlashBox for ver.Zhongyou(???)
 Description : CFbListItem implementation
 ============================================================================
 */

#include "FbListData.h"
#include "Flashbox4.mbg"
#include "jpg2bitmap.h"
#include <Stringloader.h>
#include <UTF.H> //Link against: charconv.lib 
#include "XmlNode.h"


CFbListData::CFbListData(TInt aItemId)
{
	// No implementation required
	m_ItemId = aItemId;
	m_isShowDescript = EFalse;
}

CFbListData::~CFbListData()
{
	delete m_pSmallIcon;//小图标
	delete m_pLargeIcon;//大图标
	delete m_pItemTitle;//标题
	delete m_pItemDescript;//描述
	delete m_pIconUrl;
	delete m_pMulImage;
	delete static_cast<CXmlNode*>(m_pDataBlock);
}

/**
 * EPOC default constructor for performing 2nd stage construction
 */
void CFbListData::ConstructL (const TInt &aTitleResId, const TInt &aDescriptResId)
{
	if(aTitleResId != 0)
		m_pItemTitle = StringLoader::LoadL(aTitleResId);
	if(aDescriptResId != 0)
		m_pItemDescript = StringLoader::LoadL(aDescriptResId);
}

/**
 * 
 */
void CFbListData::ConstructL (const TDesC &aTitle, const TDesC &aDescript)
{
	if(aTitle != KNullDesC)
	{
		m_pItemTitle = HBufC::New(aTitle.Length());
		m_pItemTitle->Des().Copy(aTitle);
	}
	if(aDescript != KNullDesC)
	{
		m_pItemDescript = HBufC::NewL(aDescript.Length());
		m_pItemDescript->Des().Copy(aDescript);
	}
	
}

/**
 * 
 */
void CFbListData::ConstructL (const TDesC8 &aTitle, const TDesC8 &aDescript)
{
	if (aTitle != KNullDesC8 )
	{
		m_pItemTitle = CnvUtfConverter::ConvertToUnicodeFromUtf8L(aTitle);
	}
	if (aDescript != KNullDesC8 )
	{
		m_pItemDescript = CnvUtfConverter::ConvertToUnicodeFromUtf8L(aDescript);
	}
}

/**
 * create item's icon by bitmap instance
 */
void CFbListData::SetItemIcons (CFbsBitmap * pSmall, CFbsBitmap *pLarge)
{
	m_pSmallIcon = pSmall;
	m_pLargeIcon = pLarge;
}

/**
 * create item's icon by file path
 */
void CFbListData::SetItemIconsL (const TDesC &aSmallPath, const TDesC &aLargePath)
{
	m_pSmallIcon = CJpg2Bitmap::BitmapFromJpgFile(aSmallPath);
	m_pLargeIcon = CJpg2Bitmap::BitmapFromJpgFile((aLargePath));
}

/**
 * 
 */
TInt CFbListData::GetItemId ()
{
	return m_ItemId;
}

/**
 * 
 */
HBufC *CFbListData::GetTitle ()
{
	return m_pItemTitle;
}

/**
 *
 */
HBufC* CFbListData::GetDescript ()
{
	return m_pItemDescript;
}

/**
 * set the descript to show or disshow
 */
void CFbListData::SetDescriptShow (TBool isShow )
{
	m_isShowDescript = isShow;
}

/**
 * 
 */
TBool CFbListData::IsShowDescript ()
{
	return m_isShowDescript;
}

/**
* 
 */
void CFbListData::SetIconUrl(const TDesC8 &iconUrl )
{
	if(iconUrl.Length() > 0)
	{
		m_pIconUrl = iconUrl.Alloc();
		
		if (m_pMulImage )
		{
			delete m_pMulImage;
			m_pMulImage = NULL;
			
		}
		m_pMulImage = new (ELeave) CMulImage (this );
		m_pMulImage->OpenDataL (iconUrl );
	}
}

/**
 * 
 */
void CFbListData::MulImageReady (CMulImage *pImage )
{
	if(pImage && pImage->GetBitmap())
	{
		delete m_pLargeIcon;
		m_pLargeIcon = NULL;
	}
}

